package cn.edu.zafu.bigdata.lb;
/**
 * ArrayIndexOutOfBoundsExceptionExample - 处理数组下标越界异常的示例程序
 * @author LiuBo
 */
public class ArrayIndexOutOfBoundsExceptionExample {

    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5};
        try {
            int element = getElement(arr, 10);
            System.out.println("元素是: " + element);
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("错误: " + e.getMessage());
        }
    }

    public static int getElement(int[] arr, int index) {
        if (index < 0 || index >= arr.length) {
            throw new ArrayIndexOutOfBoundsException("索引超出数组范围");
        }
        return arr[index];
    }
}